import { useMessage, useDialog } from 'naive-ui';
import { useI18n } from 'vue-i18n';

export function useI18nHook() {
  const { t: $t, locale } = useI18n();

  return { $t, locale };
}

export function messageHooks() {
  const message = useMessage();
  const dialog = useDialog();

  const dialogConfig = {
    title: '提示',
    positiveText: '确定',
    negativeText: '取消',
    maskClosable: false,
  };

  const IDialog = {
    success(text = '', onPositiveClick: Function, onNegativeClick?: Function) {
      dialog.success({
        ...dialogConfig,
        content: text,
        onPositiveClick,
        onNegativeClick,
      });
    },
    info(text = '', onPositiveClick: Function, onNegativeClick?: Function) {
      dialog.info({
        ...dialogConfig,
        content: text,
        onPositiveClick,
        onNegativeClick,
      });
    },
    warning(text = '', onPositiveClick: Function, onNegativeClick?: Function) {
      dialog.warning({
        ...dialogConfig,
        content: text,
        onPositiveClick,
        onNegativeClick,
      });
    },
    error(text = '', onPositiveClick: Function, onNegativeClick?: Function) {
      dialog.error({
        ...dialogConfig,
        content: text,
        onPositiveClick,
        onNegativeClick,
      });
    },
  };

  return { message, dialog, IDialog };
}
